<template>
<div>
  <ul>
    <li><div>优惠券名称</div><div class="zy"><el-input v-model="name" placeholder="优惠券名称"></el-input></div></li>
    <li><div>优惠券的金额</div><div class="zy"><el-input v-model="money" placeholder="优惠券的金额"></el-input></div><div class="zy">此券可抵的金额</div></li>
    <li><div>订单金额</div><div class="zy"><el-input v-model="orderMoney" placeholder="订单金额"></el-input></div><div class="zy">订单满多少可以用</div></li>
    <li>
      <div class="block">
        <span class="demonstration">活动时间</span>
      <el-date-picker
              class="zy"
              v-model="value1"
              type="datetimerange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['12:00:00']"
              :default-value="new Date()">
      </el-date-picker>
    </div>
    </li>
    <li><div>发放的数量</div><div class="zy"><el-input v-model="number" placeholder="发放的数量"></el-input></div></li>
    <li><el-button type="primary" @click="couponAdd">确定</el-button></li>
  </ul>
</div>
</template>

<script>
export default {
name: "add",
  inject:['reload'],
  data(){
  return{
    name:'',
    money:'',
    orderMoney:'',
    number:'',
    newDate:'',
    value1: [new Date(2021, 3, 28, 10, 10), new Date(2021, 4, 10, 10, 10)],
  }
  },
  mounted() {
  let dataDate=new Date();
  this.newDate=dataDate;
  console.log(this.newDate);
  },
  methods: {
    couponAdd: function () {
      this.value1[0]=this.value1[0].getFullYear() + '-' + (this.value1[0].getMonth() + 1) + '-' + this.value1[0].getDate() + ' ' + this.value1[0].getHours() + ':' + this.value1[0].getMinutes() + ':' + this.value1[0].getSeconds();
      this.value1[1]=this.value1[1].getFullYear() + '-' + (this.value1[1].getMonth() + 1) + '-' + this.value1[1].getDate() + ' ' + this.value1[1].getHours() + ':' + this.value1[1].getMinutes() + ':' + this.value1[1].getSeconds();
      console.log(this.name,this.money,this.orderMoney,this.value1[0],this.value1[1],this.number)
          this.$axios.post('/api/coupon/addCouponShow',{couponShowName:this.name,couponShowMoney:this.money,couponShowMinimoney:this.orderMoney,couponStartTime:this.value1[0],couponEndTime:this.value1[1],couponShowMax:this.number}).then((res)=>{
            console.log(res.data);
            if (res.data.code==200){
              this.$message({
                message: res.data.msg,
                type: 'success'
              });
            }else {
              this.$message({
                message: res.data.msg,
              });
            }
            this.reload();
          });
      },
    change(val){
      console.log(val)
    }
   }
}
</script>

<style scoped>
ul li{
  list-style-type: none;
  display: flex;
  align-items: center;
  height: 100px;
  width: 500px;
}
.zy{
  margin-left: 20px;
}
</style>